package com.bocai.eelly.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.eelly.R;
import com.bocai.eelly.activitys.ChangePsdActivity;
import com.bocai.eelly.activitys.FeedbackActivity;
import com.bocai.eelly.activitys.UserPerfectInformationActivity;
import com.bocai.eelly.common.BaseFragment;
import com.bocai.eelly.utils.SP;

import butterknife.Bind;
import butterknife.ButterKnife;

public class UserFragment extends BaseFragment implements View.OnClickListener {
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.ll_user_perfect_information)
    LinearLayout llUserPerfectInformation;
    @Bind(R.id.ll_user_change_psd)
    LinearLayout llUserChangePsd;
    @Bind(R.id.ll_user_clear)
    LinearLayout llUserClear;
    @Bind(R.id.ll_user_feedback)
    LinearLayout llUserFeedback;
    @Bind(R.id.tv_user_name)
    TextView tvUserName;
    @Bind(R.id.tv_user_phone)
    TextView tvUserPhone;
    private View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_user, null);
        initView();
        initEvnet();
        return view;

    }

    private void initEvnet() {
        llUserPerfectInformation.setOnClickListener(this);
        llUserChangePsd.setOnClickListener(this);
        llUserClear.setOnClickListener(this);
        llUserFeedback.setOnClickListener(this);
    }

    private void initView() {
        ButterKnife.bind(this, view);
        tvTitle.setText(R.string.str_title_user);
        tvUserName.setText(SP.get(getActivity(),"username","无昵称").toString());
        String phone=SP.get(getActivity(),"phone","无电话").toString();
        phone= phone.substring(0,phone.length()-(phone.substring(3)).length())+"****"+phone.substring(7);
        tvUserPhone.setText(phone);
        toolbar.inflateMenu(R.menu.menu_user);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_user_perfect_information:
                startActivity(new Intent(getActivity(), UserPerfectInformationActivity.class));
                break;
            case R.id.ll_user_change_psd:
                Intent intent=new Intent(getActivity(), ChangePsdActivity.class);
                intent.putExtra("what","changepsd");
                startActivity(intent);
                break;
            case R.id.ll_user_clear:
                break;
            case R.id.ll_user_feedback:
                startActivity(new Intent(getActivity(), FeedbackActivity.class));
                break;
        }
    }
}
